﻿using B.S.Data.MES.API.Applications.QualityManagement.ExamineTypeModel.Command;
using B.S.Domain.BasicData.QualityManagement;
using B.S.Infratrctrue;
using B.S.Requst;
using MediatR;
using Microsoft.AspNetCore.Mvc.ApiExplorer;


namespace B.S.Data.MES.API.Applications.QualityManagement.ExamineTypeModel.CommandHandler
{
    /// <summary>
    /// 新增检验类型命令处理
    /// </summary>
    public class CreateExamineTypeCommandHandler : IRequestHandler<CreateExamineTypeCommand, APIRequst<int>>
    {
        private readonly IBaseRepository<ExamineType> _examinetypeRepository;
        public CreateExamineTypeCommandHandler(IBaseRepository<ExamineType> examinetypeRepository)
        {
            _examinetypeRepository = examinetypeRepository;

        }
        public  async Task<APIRequst<int>> Handle(CreateExamineTypeCommand request, CancellationToken cancellationToken)
        {
            APIRequst<int> result = new APIRequst<int>();
            result.Code = RequstCode.成功;
            result.Msg=RequstCode.成功.ToString();
            ExamineType type = new ExamineType();
            type.ExamineNo = request.ExamineNo;
            type.ExamineName = request.ExamineName;
            type.ExamineDesc = request.ExamineDesc;
            type.CreateName = request.CreateName;
            type.CreateTime = DateTime.Now;

            await _examinetypeRepository.Add(type);

            return await Task.FromResult(result);


        }
    }
}
